package com.zyf.pattern.observer.core;

import java.lang.reflect.Method;

/**
 * 事件
 * 监听器的一种包装
 * create by yifeng
 */
public class Event {
    // 事件源,事件是由谁发起
    private Object source;

    // 通知目标，通知谁
    private Object target;

    //回调,事件触发后，要做什么动作
    private Method callback;

    // 触发,事件名称，触发的是什么事件
    private String trigger;
    // 时间触发的时间
    private long time;

    public Event(Object target, Method callback) {
        this.target = target;
        this.callback = callback;
    }

    void setTime(long time) {
        this.time = time;
    }

    public Object getSource() {
        return source;
    }

    void setSource(Object source) {
        this.source = source;
    }

    public Object getTarget() {
        return target;
    }

    public void setTarget(Object target) {
        this.target = target;
    }

    public Method getCallback() {
        return callback;
    }

    public void setCallback(Method callback) {
        this.callback = callback;
    }

    public String getTrigger() {
        return trigger;
    }

    Event setTrigger(String trigger) {
        this.trigger = trigger;
        return this;
    }

    @Override
    public String toString() {
        return "\nEvent{" +
                "\t source=" + source + ",\n" +
                "\t  target=" + target + ",\n" +
                "\t  callback=" + callback + ",\n" +
                "\t  trigger='" + trigger + '\'' + "\n" +
                '}';
    }
}
